package com.iot.service;

import com.iot.mapper.Trole_authorityMapper;
import com.iot.pojo.MTrole_authority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Trole_authorityServiceImpl implements Trole_authorityService {
    @Autowired
    private Trole_authorityMapper mapper;
    @Override
    public int getRecordCount(String sWhere) {
        return mapper.getRecordCount(sWhere);
    }

    @Override
    public int insert(MTrole_authority mTrole_authority) throws Exception {
        int count = 0;
        count = getRecordCount(" AND MENU_ID='" + mTrole_authority.getMENU_ID() + "' AND ROLE_ID=" + mTrole_authority.getROLE_ID() + "");
        if (count > 0)
            throw new Exception("该权限已存在");
        return mapper.insert(mTrole_authority);
    }

    @Override
    public void update(MTrole_authority mTrole_authority) throws Exception {
        int count = 0;
        count = getRecordCount(" AND MENU_ID='" + mTrole_authority.getMENU_ID() + "' AND ROLE_ID=" + mTrole_authority.getROLE_ID() + " AND ROLE_AUTHORITY_ID!="+mTrole_authority.getROLE_AUTHORITY_ID());
        if (count > 0)
            throw new Exception("该权限已存在");
        mapper.update(mTrole_authority);
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public MTrole_authority single(Integer id) {
        return mapper.single(id);
    }

    @Override
    public List<MTrole_authority> fetch(String sWhere) {
        return mapper.fetch(sWhere);
    }
}
